from typing import List, Optional
from pydantic import BaseModel
from datetime import datetime

from app.schemas.user import UserBrief

# 营地图片基础模式
class CampsiteImageBase(BaseModel):
    url: str
    description: Optional[str] = None
    order: int = 0

# 创建营地图片
class CampsiteImageCreate(CampsiteImageBase):
    pass

# 营地图片信息
class CampsiteImage(CampsiteImageBase):
    id: int
    campsite_id: int
    created_at: datetime
    
    class Config:
        orm_mode = True

# 营地基础模式
class CampsiteBase(BaseModel):
    name: str
    description: str
    address: str
    latitude: Optional[float] = None
    longitude: Optional[float] = None
    cover_image: Optional[str] = None
    phone: Optional[str] = None
    website: Optional[str] = None
    business_hours: Optional[str] = None
    price_range: Optional[str] = None
    facilities: Optional[str] = None

# 创建营地
class CampsiteCreate(CampsiteBase):
    images: Optional[List[CampsiteImageCreate]] = []

# 更新营地
class CampsiteUpdate(BaseModel):
    name: Optional[str] = None
    description: Optional[str] = None
    address: Optional[str] = None
    latitude: Optional[float] = None
    longitude: Optional[float] = None
    cover_image: Optional[str] = None
    phone: Optional[str] = None
    website: Optional[str] = None
    business_hours: Optional[str] = None
    price_range: Optional[str] = None
    facilities: Optional[str] = None
    is_verified: Optional[bool] = None
    is_active: Optional[bool] = None
    merchant_id: Optional[int] = None

# 营地简要信息
class CampsiteBrief(BaseModel):
    id: int
    name: str
    address: str
    cover_image: Optional[str] = None
    is_verified: bool
    latitude: Optional[float] = None
    longitude: Optional[float] = None
    follower_count: int = 0
    post_count: int = 0
    
    class Config:
        orm_mode = True

# 完整营地信息
class Campsite(CampsiteBase):
    id: int
    is_verified: bool
    is_active: bool
    merchant_id: Optional[int] = None
    created_at: datetime
    updated_at: Optional[datetime] = None
    images: List[CampsiteImage] = []
    follower_count: int = 0
    post_count: int = 0
    
    class Config:
        orm_mode = True

# 营地关注信息
class CampsiteFollow(BaseModel):
    id: int
    user_id: int
    campsite_id: int
    created_at: datetime
    user: Optional[UserBrief] = None
    
    class Config:
        orm_mode = True 